class Solution
{
public:
    int minDays(int n)
    {
        unordered_map<int, int> m;
        m[1] = 1;
        m[2] = 2;
        m[3] = 2;
        function<int(int)> f = [&](int x)
        {
            if (m.count(x))
            {
                return m[x];
            }
            int result = min(1 + f(x / 2) + (x & 1), 1 + f(x / 3) + (x % 3));
            m[x] = result;
            return result;
        };
        return f(n);
    }
};